<template>
  <div class="navbar">
    <div class="right-menu">
      <div class="back-btn" @click="backDashBoard">
        返回Dashboard
      </div>
      <div class="avatar-wrapper cursor-p pr20 flex align-center" @click="logout">
        <img src="@/assets/logout.png" alt="" class="logout-img">
        <span style="font-size: 15px;color:#277fd6">退出</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import Screenfull from '@/components/Screenfull'
import Search from '@/components/HeaderSearch'
import { noticeList, readNotice } from '@/api/process/notice'
export default {
  components: {
    Breadcrumb,
    Hamburger,
    Screenfull,
    Search
  },
  data() {
    return {
      tableData: [],
      noMore: false,
      pageIndex: 1,
      pageSize: 9999
    }
  },
  mounted() {
    // this.getNoticeData()
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar', 'device', 'name']),
    isNotice() {
      let noticeState = false
      const result = []
      let count = 0
      this.tableData.forEach(item => {
        if (item.is_read == 0) {
          noticeState = true
          count = count + 1
        }
      })
      result[0] = noticeState
      result[1] = count
      return result
    }
  },
  methods: {
    backDashBoard() {
      this.$router.push('/')
    },
    async getNoticeData() {
      const table = await noticeList({
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      })
      if (table.code == 200) {
        this.tableData = [...this.tableData, ...table.data.list]
        this.pageIndex = table.data.pageIndex + 1
        this.pageSize = table.data.pageSize
        if (table.data.list.length == 0) {
          this.noMore = true
        }
      }
    },
    async jumpTodo(item) {
      const res = await readNotice({ id: item.id })
      if (res.code == 200) {
        this.pageIndex = 1
        this.tableData = []
        this.getNoticeData()
        if (item.process == 2) {
          this.$router.push('/annual/todo')
        } else {
          this.$router.push('/project/upcoming')
        }
      }
    },
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    backToNav() {
      this.$router.push('/')
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('user/LogOut').then(() => {
          location.reload()
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .logout-img{
    width: 30px;
    height:30px;
    margin-right:10px
  }

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;
    display: flex;
    flex-direction: row;
    align-items: center;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 20px;

      .avatar-wrapper {
        display: flex;
        flex-direction: row;
        align-items: center;

        .user-avatar {
          cursor: pointer;
          width: 28px;
          height: 28px;
          border-radius: 50%;
        }

        .el-icon-caret-bottom {
          cursor: pointer;

          font-size: 12px;
        }
      }
    }
  }
}

.infinite-list {
  height: 460px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.messageimg {
  width: 32px;
  height: 32px;
  align-self: flex-start;
}
.pointer {
  width: 8px;
  height: 8px;
  background: #dd2f2b;
  border-radius: 50%;
}
.pointer-no {
  width: 8px;
  height: 8px;
}
.infinite-list .infinite-list-item {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px;
  color: #606060;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  padding: 10px 0;
}
.infinite-list .infinite-list-item + .list-item {
  margin-top: 10px;
}

.back-btn {
  background:#0DB974;
  width: 150px;
  height:30px;
  color: #fff;
  border-radius:30px;
  line-height:30px;
  margin-right:20px;
  text-align:center;
  cursor:pointer;
}
</style>
